package com.qcq.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.qcq.springcloud.clients.UserFeignApi;
import com.qcq.springcloud.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：qcq
 * @date ：Created in 2020/11/27 19:34
 * @description：
 */
@RestController
@RequestMapping("feign")
public class FeignController {

    @Autowired
    private UserFeignApi userFeignApi;

    @GetMapping("{username}")
//    @HystrixCommand(fallbackMethod = "queryByUsernameFallBack")
    public User queryByUsername(@PathVariable("username") String username) {

//        if ("itheima".equals(username)) {
//            throw new RuntimeException("itheima");
//        }
//

        User user = userFeignApi.queryByUsername(username);
        return user;
    }

//    public User queryByUsernameFallBack(String name) {
//        User user = new User();
//        user.setName("服务已暂停");
//        return user;
//    }
}
